import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

class PlayerImporter {
    public static List<Player> importAllPlayersFromDatabase() {
        List<Player> players = new ArrayList<>();
        DBConnectionManager dbManager = new DBConnectionManager();
        Connection conn = dbManager.getConnection();

        if (conn != null) {
            try {
                String query = "SELECT Name, UID, Money FROM Player";
                PreparedStatement statement = conn.prepareStatement(query);
                ResultSet resultSet = statement.executeQuery();

                while (resultSet.next()) {
                    Player player = new Player();
                    player.setName(resultSet.getString("Name"));
                    player.setUid(resultSet.getInt("UID"));
                    player.setMoney(resultSet.getInt("Money"));
                    players.add(player);
                }

                resultSet.close();
                statement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                dbManager.closeConnection(conn);
            }
        }

        return players;
    }


}
